package com.tianji.controller;

import com.tianji.common.annotations.NoWrapper;
import com.tianji.dto.ChatDTO;
import com.tianji.service.ChatService;
import com.tianji.vo.ChatEventVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

@Slf4j
@RestController
@RequestMapping("/chat")
@RequiredArgsConstructor
public class ChatController {

    private final ChatService chatService;

    /**
     * 聊天,流式对话
     *
     * @param chatDTO
     * @return
     */
    @NoWrapper // 标记结果不进行包装
    @PostMapping(produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<ChatEventVO> chat(@RequestBody ChatDTO chatDTO) {
//        return this.chatService.chatStopCurrentMap(chatDTO.getQuestion(), chatDTO.getSessionId());
        return this.chatService.chat(chatDTO.getQuestion(), chatDTO.getSessionId());
    }

    /**
     * 停止对话
     *
     * @param sessionId
     */
    @PostMapping("/stop")
    public void stop(@RequestParam("sessionId") String sessionId) {
       // this.chatService.stopCurrentMap(sessionId);
        this.chatService.stop(sessionId);
    }


}